// 演示 lodash
// first / last / toUpper / reverse / each / includes / find / findIndex

const _ = require("lodash");

let arr = ['jack', 'tom', 'lucy', 'kate'];

// first : Gets the first element of array.
console.log(_.first(arr));

// last: Gets the last element of array.
console.log(_.last(arr));

// toUpper: Converts string, as a whole, to upper case just like String#toUpperCase.
console.log(_.toUpper(_.first(arr)));

// reverse: Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
// Note: This method mutates array and is based on Array#reverse.
console.log(_.reverse(arr)); // 会改变原数组

// each: Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: 
// (value, index | key, collection).Iteratee functions may exit iteration early by explicitly returning false.
console.log(_.each(arr));

// includes：Checks if value is in collection. If collection is a string, it's checked for a substring of value, otherwise SameValueZero 
// is used for equality comparisons.If fromIndex is negative, it's used as the offset from the end of collection.
console.log(_.includes(arr, "jack1"));

// find: Iterates over elements of collection, returning the first element predicate returns truthy for. 
// The predicate is invoked with three arguments: (value, index | key, collection).
console.log(_.find(arr, "tom"));

// findIndex: This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
console.log(_.findIndex(arr, "tom"));